package com.du.ssm.pojo;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : DuJiabao
 * @Project : ssm
 * @Time : 2021/4/11 23:23
 * @Desc : 用于返回json的统一对象
 */
public class Message {
  private String message;
  // 返回状态码，100 成功，200 失败
  private Status code;
  private Map<String, Object> extend = new HashMap<>();

  public Message add(String key, Object value) {
    extend.put(key, value);
    return this;
  }

  public static Message getFailureMessage() {
    return getFailureMessage("fail", null);
  }

  public static Message getFailureMessage(String message, Map<String,  Object> extend) {
    return new Message(message, Status.failure, extend);
  }

  public static Message getSuccessMessage() {
    return getSuccessMessage("success", null);
  }

  public static Message getSuccessMessage(String message, Map<String, Object> extend) {
    return new Message(message, Status.success, extend);
  }

  public Message() {
  }

  public Message(String message, Status code, Map<String, Object> extend) {
    this.message = message;
    this.code = code;
    if (extend != null) {
      this.extend = extend;
    }
  }

  public String getMessage() {
    return message;
  }

  public void setMessage(String message) {
    this.message = message;
  }

  public Status getCode() {
    return code;
  }

  public void setCode(Status code) {
    this.code = code;
  }

  public Map<String, Object> getExtend() {
    return extend;
  }

  public void setExtend(Map<String, Object> extend) {
    this.extend = extend;
  }

  public enum Status {
    success,
    failure,
    unknown
  }

  @Override
  public String toString() {
    return "Message{" +
            "message='" + message + '\'' +
            ", code=" + code +
            ", extend=" + extend +
            '}';
  }
}
